<?php
/**
* 名称：合作展会模块控制器。
* 描述：合作展会模块相关的控制响应程式。
*/
final class Controller_Exhibition extends Controller{
    /**
    * 描述：主页视图程式。
    * @access protected
    * @return void
    */
    protected function Main(){
        $data=array(
            'base'=>array(
                'recommend'=>array(
                    'Name'=>'特别推荐',
                    'Row'=>Model_Exhibition::MakeLinkForDetail(self::$Database->GetRow(
                        'SELECT * FROM '.self::$Database->Table('exhibition').' ORDER BY datetime DESC'
                    ))
                ),
                'list'=>array(
                    'Name'=>'合作展会',
                    'Link'=>Route::MakeHyperlink(':exhibition::listview'),
                    'Rows'=>Model_Exhibition::MakeLinkForDetail(self::$Database->GetAll(
                        'SELECT * FROM '.self::$Database->Table('exhibition').' ORDER BY datetime DESC'
                    ))
                ),
                'ad'=>Model_Ad::Exhibition(),
                'slide'=>Model_Slide::Exhibition()
            )
        );
        //~
        self::$Template->Assign('data',$data);
        self::$Template->Display('exhibition/index.html');
    }

    /**
    * 描述：列表视图程式。
    * @access protected
    * @return void
    */
    protected function Listview(){
        $data=array(
            'base'=>array(
                'list'=>self::$Database->GetLimit(
                    'SELECT * FROM '.self::$Database->Table('exhibition').' ORDER BY datetime DESC'
                    ,Route::GetArguments('page'),20
                ),
                'ad'=>Model_Ad::Exhibition()
            ),
        );
        //-
        $data['base']['list']['arguments']=array(
            'industy'=>0
        );
        $data['base']['list']['Rows']=Model_Exhibition::MakeLinkForDetail(
            $data['base']['list']['Rows']
        );
        //~
        self::$Template->Assign('data',$data);
        self::$Template->Display('exhibition/list.html');
    }

    /**
    * 描述：详细视图程式。
    * @access protected
    * @return void
    */
    protected function Detail(){
        $arguments=array(
            'id'=>(int)Route::GetArguments('id')
        );
        //~
        $data=array(
            'base'=>array(
                'main'=>self::$Database->GetRow(
                    'SELECT * FROM '.self::$Database->Table('exhibition').' WHERE id=?',
                    array($arguments['id'])
                ),
                'ad'=>Model_Ad::Exhibition()
            )
        );
        //~
        if(empty($data['base']['main'])){
            Route::Http404();
            return;
        }
        //~
        self::$Template->Assign('data',$data);
        self::$Template->Display('exhibition/detail.html');
    }

    /**
    * 描述：绑定横幅幻灯片数据。
    * @access protected
    * @return void
    */
    protected function Slide(){
        $data=self::$Database->GetAll('SELECT * FROM '.self::$Database->Table('slide').' WHERE type=\'exhibition\' ORDER BY id DESC LIMIT 0,5'); //,7,8
        $xml='<?xml version="1.0" encoding="utf-8"?>';
        $xml.='<bcaster autoPlayTime="3">';
        foreach ($data as $row) {
            $xml.='<item item_url="/data/000/slide/'.$row['picture'].'" link="'.$row['link'].'"></item>';
        }
        $xml.='</bcaster>';
        //~
        header("Content-type:text/xml");
        echo $xml;
    }
}